package com.mew.chess.core.game.yxx.game.common;


import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 牌类型
 */
public enum YxxType {

    Fish(1, "鱼"),
    Shrimp(2, "虾"),
    Crab(3, "蟹"),
    Tiger(4, "虎"),
    Gourd(5, "葫芦"),
    Chicken(6, "鸡");

    private final int code;
    private final String desc;

    private YxxType(final int code, final String desc) {
        this.code = code;
        this.desc = desc;
    }

    private final static Map<Integer, YxxType> stateMap
            = Arrays.stream(YxxType.values()).collect(Collectors.toMap(YxxType::code, code -> code));


    public int code() {
        return this.code;
    }

    public String desc() {
        return this.desc;
    }

    /**
     * @param code 代码
     * @return 转换出来的状态码
     */
    public static YxxType parse(int code) {
        return stateMap.get(code);
    }

    public static YxxType[] create(int...types){
        YxxType[] yxxTypes = new YxxType[types.length];

        for (int i = 0; i < types.length; i++) {
            yxxTypes[i] = parse(types[i]);
        }

        return yxxTypes;
    }
}
